﻿using System;
using System.Collections.Generic;
using System.Text;

namespace lxwmvc
{
    using System;
    using System.Xml;
    using System.Web;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Dynamic;
    /// <summary>
    /// 定义全局变量
    /// </summary>
    public class globalhelper
    {



        /// <summary>
        /// 功能:用户globalhelper中的其他键值
        /// [11-03-10 13:52  周四 lxw]<para />
        /// </summary>
        public class item
        {
            public string this[string key]
            {
                get
                {
                    if (HttpContext.Current.Session[key] != null) return HttpContext.Current.Session[key].tostr();
                    return cookieshelper.getcookie(key).tostr();
                }
                set
                {
                    HttpContext.Current.Session[key] = value.tostr();
                    cookieshelper.setcookie(key, value.ToString());
                }
            }
        }
        /// <summary>
        /// 功能:当前用户id，数据库中唯一
        /// [11-03-10 13:38  周四 lxw]<para />
        /// [09.6.11 hl]<para />
        /// </summary>
        public static int yonghuid
        {
            get
            {
                if (HttpContext.Current.Session["YongHuID"] != null) return HttpContext.Current.Session["YongHuID"].toint32();
                return cookieshelper.getcookie("YongHuID").toint32();
            }
            set
            {
                HttpContext.Current.Session["YongHuID"] = value.tostr();
                cookieshelper.setcookie("YongHuID", value.ToString());
            }
        }

        /// <summary>
        /// KeHuID
        /// </summary>
        public static int kehuid
        {
            get
            {
                if (HttpContext.Current.Session["KeHuID"] != null) return HttpContext.Current.Session["KeHuID"].toint32();
                return cookieshelper.getcookie("KeHuID").toint32();
            }
            set
            {
                HttpContext.Current.Session["KeHuID"] = value.tostr();
                cookieshelper.setcookie("KeHuID", value.ToString());
            }
        }

        public static string cookies_sysname
        {
            get
            {
                return globalhelper.getkey("cookies_sysname");
            }
            set
            {
                globalhelper.setkey("cookies_sysname", value);
            }
        }
        public static string cookies_themes
        {
            get
            {
                return globalhelper.getkey("cookies_themes");
            }
            set
            {
                globalhelper.setkey("cookies_themes", value);
            }
        }

        public static string cookies_jsver
        {
            get
            {
                return globalhelper.getkey("cookies_jsver");
            }
            set
            {
                globalhelper.setkey("cookies_jsver", value);
            }
        }

        static string getkey(string key)
        {
            if (HttpContext.Current.Session[key] != null)
                return HttpContext.Current.Session[key].tostr();
            return cookieshelper.getcookie(key).tostr();
        }
        static void setkey(string key, object value)
        {
            HttpContext.Current.Session[key] = value.tostr();
            cookieshelper.setcookie(key, value.ToString());
        }


        public static int guanliyuanid
        {
            get
            {
                if (HttpContext.Current.Session["guanliyuanid"] != null) return HttpContext.Current.Session["guanliyuanid"].toint32();
                return cookieshelper.getcookie("guanliyuanid").toint32();
            }
            set
            {
                HttpContext.Current.Session["guanliyuanid"] = value.tostr();
                cookieshelper.setcookie("guanliyuanid", value.ToString());
            }
        }

        public static string guanliyuan
        {
            get
            {
                if (HttpContext.Current.Session["guanliyuan"] != null) return HttpContext.Current.Session["guanliyuan"].tostr();
                return cookieshelper.getcookie("guanliyuan").tostr();
            }
            set
            {
                HttpContext.Current.Session["guanliyuan"] = value.tostr();
                cookieshelper.setcookie("guanliyuan", value.ToString());
            }
        }

        /// <summary>
        /// 功能:当前用户名，数据库中不唯一,用户名在同一个单位是唯一的，登录的时候使用用户名登录
        /// [09.6.11 hl]<para />
        /// </summary>
        public static string yonghuming
        {
            get { return cookieshelper.getcookie("YongHuMing"); }
            set { cookieshelper.setcookie("YongHuMing", value); }
        }

        /// <summary>
        /// 功能:当前用户真实姓名
        /// [09.6.11 hl]<para />
        /// </summary>
        public static string yonghuxingming
        {
            get { return cookieshelper.getcookie("YongHuXingMing"); }
            set { cookieshelper.setcookie("YongHuXingMing", value); }
        }

        /// <summary>
        /// 权限字符串
        /// </summary>
        public static string powerstring
        {
            //TODO:2013.01.01
            get
            {
                if (HttpContext.Current.Session["powerstring"] != null)
                    return HttpContext.Current.Session["powerstring"].tostr();
                else
                {

                    ////这里的ID是管理员ID,这里有调整 20120216 lxw 调整权限
                    if (cookieshelper.getcookie("jueseid").toint32(0) == 0)
                    {
                        return "'-1'";
                        //throw new Exception("AAA:没有权限!");
                    }
                    else
                    {
                        int jueseid = cookieshelper.getcookie("jueseid").toint32(0);
                        applicationhelper.setpowerstring(jueseid);
                        HttpContext.Current.Session["powerstring"] = globalhelper.powerstring;

                        return globalhelper.powerstring;
                    }
                }
            }
            set
            {
                HttpContext.Current.Session["powerstring"] = value;
            }
        }


        /// <summary>
        /// 用户角色
        /// [09.12.28 于坤]<para />
        /// </summary>
        public static String jueseid
        {
            get
            {
                if (HttpContext.Current.Session["JueSeID"] != null) return HttpContext.Current.Session["JueSeID"].tostr();
                return cookieshelper.getcookie("JueSeID").tostr();
            }
            set
            {
                HttpContext.Current.Session["JueSeID"] = value.tostr();
                cookieshelper.setcookie("JueSeID", value.ToString());
            }
        }



        /// <summary>
        /// 功能:给指定的Key赋值和取值，操作cookies
        /// [11-03-10 13:49  周四 lxw]<para />
        /// </summary>
        public static item Item = new item();


        /// <summary>
        /// 功能:缓存每页大小，对一个用户来讲，这是全局的信息
        /// [11-03-10 13:44  周四 lxw]<para />
        /// [09.12.28 于坤]<para />
        /// </summary>
        public static string PageSize
        {
            get
            {
                string strPageSize = cookieshelper.getcookie("PageSize");
                if (string.IsNullOrEmpty(strPageSize))
                {
                    strPageSize = "10";
                    PageSize = strPageSize;
                }

                return strPageSize;
            }
            set { cookieshelper.setcookie("PageSize", value); }
        }



        /// <summary>
        /// 为感恩网添加 20121231
        /// </summary>
        public static int managerid
        {
            get
            {
                if (HttpContext.Current.Session["managerid"] != null) return HttpContext.Current.Session["managerid"].toint32(0);
                return cookieshelper.getcookie("managerid").toint32(0);
            }
            set
            {
                HttpContext.Current.Session["managerid"] = value;
                cookieshelper.setcookie("managerid", value.ToString());
            }
        }
    }

   
}